﻿using GodSystemCommon;
using GodSystemModel;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GodSystemDAL
{
    public class CategoriesDAL
    {
        public int AddCate(CategoriesModel cate)
        {
            string sql = "insert into categories(CateName,CreateUser) values(@CateName,@CreateUser)";
            MySqlParameter[] pms =
            {
                new MySqlParameter("@CateName",cate.CateName),
                new MySqlParameter("@CreateUser",cate.CreateUser),
            };
            return SqlHelper.ExecuteNonQuery(sql, pms);
        }

        public object CheckCateName(CategoriesModel cate)
        {
            string sql = "select count(*) as total from categories where CateName = @CateName";
            MySqlParameter[] pms =
            {
                new MySqlParameter("@CateName",cate.CateName),
            };
            return SqlHelper.ExecuteScalar(sql, pms);
        }


        public DataTable GetCategories()
        {
            string sql = "select Id,CateName,CreateUser from categories";
            return SqlHelper.ExecuteDataTable(sql, null);
        }


        public int UpdateCateName(CategoriesModel cate)
        {
            string sql = "update categories set CateName = @CateName where Id = @Id";
            MySqlParameter[] pms =
            {
                new MySqlParameter("@CateName",cate.CateName),
                new MySqlParameter("@Id",cate.Id),
            };
            return SqlHelper.ExecuteNonQuery(sql, pms);
        }
    }
}
